# current_user_uid = "111"
import requests
import global_variable
import os
from database.Database import Database
database = Database('./data.db')

from playsound import playsound
def get_new_word():
    result = database.get_word_by_id()
    return result


def get_example():
    result = database.get_example_by_v_vid()
    global_variable.set("current_user_v_number",str(int(global_variable.get("current_user_v_number"))+1))
    return result


def get_remember_record():
    result = database.get_current_user_remember_record()
    print("result",result)
    return result


def get_v_name_by_vid(vid):
    result = database.get_v_name_by_v_id(vid)
    return result

def insert_remember_record():
    database.insert_remember(global_variable.get("v_vid"))

def collect():
    database.insert_collection()

def get_collection_record():
    result = database.get_current_user_collection_record()
    print("result",result)
    return result

def play():
    word =global_variable.get("v_name")
    print("word--",word)
    print("word",word)
    url = "https://ssl.gstatic.com/dictionary/static/sounds/oxford/" + word + "--_gb_1.mp3"
    res = requests.get(url)
    with open(word+'.mp3', 'ab') as file:  # 保存到本地的文件名
        file.write(res.content)
        file.flush()
    playsound(word+'.mp3')
    # import os
    os.remove(word+'.mp3')
    # print(music)
    # print(type(music))

